<template>
  <el-dialog title="更新时间" :visible.sync="dialogFormVisible" width="400px">
    <el-form ref="formData" :rules="rules" :model="formData">
      <el-form-item  label="发货时间" prop="deliveryTime">
        <el-date-picker
            v-model="formData.deliveryTime"
            type="date" 
            size="small"
            placeholder="选择时间">
            </el-date-picker>
      </el-form-item>
    </el-form> 
    <div slot="footer" class="dialog-footer">
      <el-button
        type="primary"
        @click="submitForm('formData')"
        size="small"
        :disabled="loading"
        :icon="loading?'el-icon-loading':'el-icon-circle-plus-outline'"
      >确定</el-button>
    </div>
  </el-dialog>
</template>
<script>
const ERR_OK = 200;
export default {
  data() {
    return {
      dialogFormVisible: false,
      formData: {},
      loading: false,
      rules: {
        deliveryTime: [
          {
            required: true,
            message: "请选择时间",
            trigger: "change"
          }
        ]
      }
    };
  },
  methods: {
    show(row) {
      this.dialogFormVisible = true;
      this.formData = {
        deliveryTime:row.deliveryTime,
        visionDemandId: row.visionDemandId
      };
    },
  
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.loading = true;
          this.$ajax({
            method: "post",
            url:
              this.GLOBAL.oaVisionDemand +
              "/visionDemand/updateDeliveryTimeByVisionDemandById",
            data: this.formData
          }).then(res => {
            this.loading = false;
            if (res.data.code === ERR_OK) {
              this.$message.success(res.data.msg);
              this.dialogFormVisible = false;
              this.$emit("loadData");
            } else {
              this.$message.error(res.data.msg);
            }
          });
        } else {
          return false;
        }
      });
    }
  }
};
</script>